<?php
namespace Admin\Controller;


class StyleController extends BaseController{
	/*
	 * @discribe 风格样式管理页面
	 */
	function styleManage (){
		//查询数据库中的风格样式
		$pdoStyle= D('style');
		$arrStyle= $pdoStyle->select();
		
		$this->assign('arrStyle',$arrStyle);
		
		$this->display();
	}
	/*
	 * @discribe 风格样式启用/停用页面
	*/
	function styleChange (){
		if(!empty($_POST)){
			if($_POST['action']=='is_work'){
				if($_POST['status'] == 1){
					$_POST['status']=0;
				}else{
					$_POST['status']=1;
				}
				$pdoStyle = D('Style');			
				$ce = $pdoStyle->create(array('status'=>$_POST['status']));
				if($ce){
					$re = $pdoStyle->where(array('id'=>':id'))->bind(':id',$_POST['id'])->save();
				
					if($re !== null){
						$mes = 1;
						$this->ajaxReturn($mes);
					}else{
						$mes = 2;
						$this->ajaxReturn($mes);
					};
				}else{
					$mes = 0;
					$this->ajaxReturn($mes);
				}
			}elseif($_POST['action']=='is_delete'){
				$pdoStyle = D('Style');
				$re = $pdoStyle->where(array('id'=>':id'))->bind(':id',$_POST['id'])->delete();
					if($re !== null){
						$mes = 1;
						$this->ajaxReturn($mes);
					}else{
						$mes = 2;
						$this->ajaxReturn($mes);
					}
			}elseif($_POST['action']=='is_redact'){
				
			}
		}
	
	}
	
	/*
	 * @discribe 风格样式添加页面
	*/
	function styleAdd (){
		if(!empty($_POST)){
			
				//实例化
				$pdo = D('Style');
				//进行数据添加
				$re = $pdo->create();
				if($re){
					$result = $pdo->add();
					if($result){
						$info = array('mes'=>1,'content'=>'添加成功！');
						$this->ajaxReturn($info);
					}else{
						$info = array('mes'=>2,'content'=>'添加失败！');
						$this->ajaxReturn($info);
					}
				}else{
					$data = $pdo->getError();
					$info = array('mes'=>3,'content'=>$data);
					$this->ajaxReturn($info);
				}			
		}
		$this->display();		
	}
	function styleRedact(){
		if(!empty($_GET)){
			$this->assign('id',$_GET['id']);
		}
		$this->display();
	}
	
	
	function styleRedactSave(){
		
		 if(!empty($_POST)){
			$id=$_POST['id'];
			unset($_POST['id']);
			//实例化
			//$this->ajaxReturn($);
			$pdo = D('Style');
			//进行数据添加
			$re = $pdo->create($_POST);
			if($re){
				$result = $pdo->where(array('id'=>':id'))->bind(array(':id'=>$id))->save();

				if($result){
					$info = array('mes'=>1,'content'=>'添加成功！');
					$this->ajaxReturn($info);
				}else{
					$info = array('mes'=>2,'content'=>'添加失败！');
					$this->ajaxReturn($info);
				}
			}else{
				$data = $pdo->getError();
				$info = array('mes'=>3,'content'=>$data);
				$this->ajaxReturn($info);
			}
		} 
		
	}
}